import execjs
import os


# 如果报错：ModuleNotFoundError: No module named 'execjs'
# 使用 pip install PyExecJS 安装此工具包

def get_des_psswd(data):
    ctx = execjs.compile(jscode)
    return (ctx.call('hex_md5', data))


def get_js():
    with open('enc.js', 'r') as f:
        line = f.readline()
        htmlstr = ''
        while line:
            htmlstr = htmlstr + line
            line = f.readline()
        return htmlstr


os.system("dir")
jscode = get_js()


def get_sign(tid, infoid):
    info_str = "infoId=" + infoid
    tid_str = "&tid=" + tid
    other = "web_phone_:k?&^#:"
    sign = get_des_psswd(info_str + tid_str + other)
    return sign


if __name__ == '__main__':
    # sign: hex_md5("infoId=" + ____json4fe.infoid + "&tid=" + t + "web_phone_:k?&^#:")
    # tid的值可以随便设置最好通过其他方式获取
    # tid="&tid=82d36551-7ceb-4008-8619-b8bef425895a"

    # print(get_des_psswd("infoId=37910008976798"+tid+other))
    print(get_sign("82d36551-7ceb-4008-8619-b8bef425895a", "37910008976798"))
    print("57b1dc220338a89e51578a381b2a1d33")
